<template>
    <div>
        <a href="/Addh">新增病房</a>
        <h1>显示病房</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>病房编号</td>
                    <td>病房号</td>
                    <td>所属科室</td>
                    <td>床位总数量</td>
                    <td>状态</td>
                    <td>空闲床数量</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in date">
                    <td>{{ a.houseId }}</td>
                    <td>{{ a.houseName }}</td>
                    <td>{{ a.kHouseName }}</td>
                    <td>{{ a.zNun }}</td>
                    <td>{{ a.state?"启用":"维修" }}</td>
                    <td>{{ a.kNum }}</td>
                    <td>{{ moment(a.createTimes).format("YYYY-MM-DD HH:MM:SS") }}</td>
                    <td>
                        <input type="button" :value="a.state?'维修':'启用'" @click="upd(a.houseId)">
                    </td>
                </tr>
            </tbody>
        </table>
        <a href="/Adda">医生</a>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,onMounted } from 'vue';
onMounted(()=>{
    getdate()
    show()
})
const upd=(val:any)=>{
    if(!confirm("确认修改吗")){
        return
    }
    axios.get("/api/House/UpdState",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("修改成功")
            show()
        }
        else{
            alert("修改失败")
        }
    })
}
const show=()=>{
    axios.get("/api/House/ShowHouse",{params:date.value}).then(res=>{
        date.value=res.data
    })
}
const date=ref([{
  "houseId": 0,
  "houseName": "",
  "kHouseId": 0,
  "zNun": 0,
  "state": false,
  "kNum": 0,
  "createTimes": "",
  "kHouseName": ""
}])
const getdate=()=>{
    axios.get("/api/KHouse/Xia").then(res=>{
        data.value=res.data
    })
}
const data=ref([{
    "kHouseId": 0,
    "kHouseName": ""
}])
</script>

<style scoped>

</style>